package com.tanhua.dubbo.api.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import com.tanhua.dubbo.pojo.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0")
public class UserInfoApiImpl implements UserInfoApi {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public Boolean save(UserInfo userInfo) {
        //判断对象中的数据是否符合要求
        if (!ObjectUtil.isAllNotEmpty(userInfo.getUserId(), userInfo.getNickName())) {
            return false;
        }
        userInfo.setAge(20);
        userInfo.setEdu("本科");
        userInfo.setIndustry("计算机");
        userInfo.setMarriage("丧偶");
        userInfo.setTags("孤儿");
        return this.userInfoMapper.insert(userInfo) == 1;

    }

    @Override
    public Boolean update(UserInfo userInfo) {
        return this.userInfoMapper.update(userInfo,new QueryWrapper<UserInfo>().eq("user_id",userInfo.getUserId()))==1;
    }

    @Override
    public UserInfo queryByUserId(Long userId) {
        return this.userInfoMapper.selectOne(new QueryWrapper<UserInfo>().eq("user_id",userId));
    }

    @Override
    public List<UserInfo> queryByUserIdList(List<Object> userIdList) {
        return null;
    }
}
